// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html


import YP from "../../sound/music";
import CustomButton from "../BASE/CButton";
import ComponentBase from "../BASE/ComponentBase";
import { gif } from "../BASE/spineANDgif/gif";
import AnimalManager from "../Manager/AnimalManager";
import GeZiManager from "../Manager/GeZiManager";
import KHD from "../Message/KHD";
import MessageCenter from "../Message/MessageCenter";
import S02 from "../Scharacter/S02";
import S03 from "../Scharacter/S03";
import S06 from "../Scharacter/S06";
import S09 from "../Scharacter/S09";
import S10 from "../Scharacter/S10";
import SXX from "../Scharacter/SXX";
import A509 from "../equipment/weapon/SC/A509";
import weapon from "../equipment/weapon/weapon";

import state from "../game/time/state";
import turn from "../game/time/turn";
import TorW from "./BASEUI/TorW";
import moveUI from "./BASEUI/moveUI";
import MUI from "./MMUI/MUI";
import mouse from "./mouse";
import shopM from "./shop/ShopM";
import shops from "./shop/shops";





const {ccclass, property} = cc._decorator;

@ccclass
export default class BUI extends ComponentBase {
Sk:number=0;
    SUI:cc.Node=null;
    A1:cc.Node=null;
    A2:cc.Node=null;
    A3:cc.Node=null;
    A4:cc.Node=null;
    A5:cc.Node=null;
    MU:cc.Node=null;
    leveUP:cc.Node=null;
    changL:cc.Node=null;
    AM:cc.Node=null
   
yes:cc.Node;
DW:number=0;


NK:number=0;

@property(cc.SpriteAtlas)
   Atlas: cc.SpriteAtlas = null;
   @property(cc.SpriteAtlas)
   Atlas2: cc.SpriteAtlas = null;
   getTNC(n:number){


    let k=  GeZiManager.PCP.TNJJ
    let l =GeZiManager.TNC
   if(k[n]+l[n]>=0){return k[n]+l[n]}else {return 0}
   }


    start(): void {
















        
    function findNodeInScene(node: cc.Node, targetName: string): cc.Node | null {
        if (node.name === targetName) {
            return node;
        }
        for (let i = 0; i < node.childrenCount; i++) {
            const child = node.children[i];
            const result = findNodeInScene(child, targetName);
            if (result) {
                return result;
            }
        }
        
        return null;
     }
     let rootNode = cc.director.getScene().getChildByName("Canvas");
     this.MU=cc.find("Canvas/UIManager/magicUI");
    this.yes = findNodeInScene(rootNode, "yes");
    this.SUI= cc.find("Canvas/UIManager/shopUI/1L/A1")
 this.A1= cc.find("Canvas/UIManager/shopUI/1L/A1")
 this.A2= cc.find("Canvas/UIManager/shopUI/1L/A2")
 this.A3= cc.find("Canvas/UIManager/shopUI/1L/A3")
 this.A4= cc.find("Canvas/UIManager/shopUI/2L/XianJing")
 this.A5= cc.find("Canvas/UIManager/shopUI/2L/BCD")
 this.leveUP= cc.find("Canvas/UIManager/shopUI/3L/Leve")
 this.changL= cc.find("Canvas/UIManager/shopUI/3L/changL")

 this.AM=cc.find("Canvas/DituManager/New Node/AnimalManager")





 
if(cc.find("Canvas").getComponent(mouse).sj){
let k=cc.find("Canvas/UIManager/BUIManager/BUI")


    this.node.scale=1.3
    this.node.position=new cc.Vec3(-550,70,0)
   k.children[0].getComponent(cc.Layout).spacingX=90
   k.children[0].getComponent(cc.Layout).paddingLeft=300


   k.children[1].position=new cc.Vec3(1600,350,0)
  k.children[1].scale=0.9
 
}
}




//
TNST(){

this.node.children[0].children[1].children[0].children[1].getComponent(gif).changeF(this.getTNC(2)-1,1);

if (GeZiManager.PCP.weapon.BT&&GeZiManager.PCP.weapon.BTS==0) {this.node.children[0].children[2].children[0].children[1].getComponent(gif).changeF(1,1);}
else{this.node.children[0].children[2].children[0].children[1].getComponent(gif).changeF(this.getTNC(3)-1+GeZiManager.PCP.weapon.TNJ,1);}




if ( GeZiManager.PCP.LST==10) {
   
    let Skill =this.node.children[1]
    let Skill1=Skill.children[0].children[0]
    let Skill2=Skill.children[1].children[0]
    let Skill3=Skill.children[2].children[0]
    let Skill4=Skill.children[3].children[0]



    Skill1.active=true
    Skill2.active=true
    Skill3.active=true
    Skill4.active=true
    Skill1.children[0].opacity=255
    Skill2.children[0].opacity=255
    Skill3.children[0].opacity=255
    Skill4.children[0].opacity=255
    Skill1.parent.getComponent(CustomButton).enableButton()
    Skill2.parent.getComponent(CustomButton).enableButton()
    Skill3.parent.getComponent(CustomButton).enableButton()
    Skill4.parent.getComponent(CustomButton).enableButton()
switch (
 
  
    GeZiManager.PCP.getComponent(SXX).Snumber) {
    case "S08":
        //this.node.children[1].children[1].children[3].active=true
    
    if (GeZiManager.PCP.TN<3||GeZiManager.PCP.qi<2) {
      Skill1.parent.getComponent(CustomButton).disableButton()
      Skill1.children[0].opacity=155
    }
    if (GeZiManager.PCP.TN<1) {
        Skill2.parent.getComponent(CustomButton).disableButton() 
        Skill2.children[0].opacity=155
    }
    Skill1.children[0].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S08-T1")
    Skill2.children[0].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S08-T2")
    //this.node.children[1].children[1].children[1].active=true
    Skill1.children[3].active=false
    Skill2.children[3].active=true
    Skill2.children[3].children[0].getComponent(cc.Label).string="X"
   
    if (GeZiManager.PCP.getComponent(SXX).BL[0]==0) {
        Skill2.active=false
     }

   
   
    Skill1.children[2].getComponent(gif).changeF(2,1)
    Skill2.children[2].getComponent(gif).changeF(0,1)
    Skill3.active=false
    Skill4.active=false
    break;
    case "S01":   
     Skill1.children[0].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S01-T1")

    Skill1.children[3].children[0].getComponent(cc.Label).string=""
    Skill1.children[3].active=false

    Skill1.children[2].active=false
  
    Skill2.active=false
    Skill3.active=false
    Skill4.active=false
    break;
    case "S02":  if (GeZiManager.PCP.TN<GeZiManager.TNC[5]||GeZiManager.PCP.qi<1+GeZiManager.PCP.node.getComponent(S02).qz) {
        Skill3.parent.getComponent(CustomButton).disableButton()
        Skill3.children[0].opacity=155
    }
    if (GeZiManager.PCP.getComponent(SXX).BL[1]==0) {
        Skill1.active=false
    }  
    if (GeZiManager.PCP.getComponent(SXX).BL[3]==0) {
        Skill2.active=false
    }    
    
    if (GeZiManager.PCP.TN<3) {
        Skill1.parent.getComponent(CustomButton).disableButton()
        Skill1.children[0].opacity=155
    }
    if (GeZiManager.PCP.qi<1) {
        Skill2.parent.getComponent(CustomButton).disableButton()
        Skill2.children[0].opacity=155
    }


   // this.node.children[1].children[0].children[1].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S04-T2")
   Skill1.children[2].active=true
   Skill1.children[2].getComponent(gif).changeF(2,1)//体能
   Skill1.children[3].children[0].getComponent(cc.Label).string=""
   Skill1.children[3].active=false
    
   Skill2.children[2].active=false
   Skill2.children[2].getComponent(gif).changeF(GeZiManager.TNC[5]-1,1)//体能
   Skill2.children[3].children[0].getComponent(cc.Label).string=1+""
   Skill2.children[3].active=true



   Skill3.children[2].active=true
   Skill3.children[2].getComponent(gif).changeF(GeZiManager.TNC[5]-1,1)//体能
   Skill3.children[3].children[0].getComponent(cc.Label).string=1+GeZiManager.PCP.node.getComponent(S02).qz+""
   Skill3.children[3].active=true



   Skill4.active=false
    break;
    case "S03":   
 
    if (GeZiManager.PCP.getComponent(SXX).BL[5]==0) {
        Skill1.active=false
     }

     Skill1.children[0].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S01-T1")

    Skill1.children[3].children[0].getComponent(cc.Label).string=""
    Skill1.children[3].active=false

    Skill1.children[2].active=false
  
    Skill2.active=false
    Skill3.active=false
    Skill4.active=false
    break;
    case "S04":  if (GeZiManager.PCP.TN<4-GeZiManager.PCP.FU[3]) {
        Skill1.parent.getComponent(CustomButton).disableButton()
        Skill1.children[0].opacity=155
        
    }
        

    Skill1.children[0].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S04-T2")

    Skill1.children[2].active=true
    Skill1.children[2].getComponent(gif).changeF(3-GeZiManager.PCP.FU[3],1)//体能
    Skill1.children[3].children[0].getComponent(cc.Label).string="2X"
    Skill1.children[3].active=true
     
    

    Skill1.children[0].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S04-T2")

    Skill1.children[2].active=true
    //Skill1.children[2].getComponent(gif).changeF(3-GeZiManager.PCP.FU[3],1)//体能
    Skill1.children[3].children[0].getComponent(cc.Label).string="2X"
    Skill1.children[3].active=true





 
    Skill2.active=false
    Skill3.active=false
    Skill4.active=false





    break;



    case "S05":
        
   
    /*
    this.node.children[1].children[0].children[1].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S05-T2")
    this.node.children[1].children[0].children[2].getComponent(gif).changeF(1,1)
    this.node.children[1].children[0].children[3].active=true
    this.node.children[1].children[0].children[3].children[0].getComponent(cc.Label).string="2"
    this.node.children[1].children[1].children[3].active=false
    this.node.children[1].children[1].active=false
    this.node.children[1].children[2].active=false
    this.node.children[1].children[3].active=false
   */

    if (GeZiManager.PCP.TN<2||GeZiManager.PCP.qi<2) {
        Skill1.parent.getComponent(CustomButton).disableButton()}
        

    Skill1.children[0].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S05-T2")

    Skill1.children[2].active=true
    Skill1.children[2].getComponent(gif).changeF(1,1)//体能
    Skill1.children[3].children[0].getComponent(cc.Label).string="2"
    Skill1.children[3].active=true
     
    
 
    Skill2.active=false
    Skill3.active=false
    Skill4.active=false







    break;
    case "S06": 
    
    if (GeZiManager.PCP.TN<3||(GeZiManager.PCP.node.getComponent(S06).xll&&!GeZiManager.PCP.node.getComponent(S06).JX1.includes("S敏捷"))) {
        Skill1.parent.getComponent(CustomButton).disableButton()
        Skill1.children[0].opacity=155
        
    }
        

    Skill1.children[0].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S04-T2")

    Skill1.children[2].active=true
    Skill1.children[2].getComponent(gif).changeF(3,1)//体能
    Skill1.children[3].children[0].getComponent(cc.Label).string="3"
    Skill1.children[3].active=true
    
    if (GeZiManager.PCP.TN<3||GeZiManager.PCP.qi<2) {
        Skill2.parent.getComponent(CustomButton).disableButton()
        Skill2.children[0].opacity=155
        
    }
    if (GeZiManager.PCP.getComponent(SXX).BL[3]==0) {
        Skill2.active=false
     }

    Skill2.children[0].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S04-T2")

    Skill2.children[2].active=true
    Skill2.children[2].getComponent(gif).changeF(1,1)//体能
    Skill2.children[3].children[0].getComponent(cc.Label).string="2"
    Skill2.children[3].active=true
    
 
 
    Skill3.active=false
    Skill4.active=false





    break;
    case "S00":
        if (GeZiManager.PCP.TN<3) {
            Skill2.parent.getComponent(CustomButton).disableButton()}
            
    
        Skill2.children[0].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S05-T2")
    
        Skill2.children[2].active=true
        Skill2.children[2].getComponent(gif).changeF(2,1)//体能
        Skill2.children[3].children[0].getComponent(cc.Label).string=""
        Skill2.children[3].active=true
    
    
    if (GeZiManager.PCP.TN<3||GeZiManager.PCP.qi<1) {
        Skill2.parent.getComponent(CustomButton).disableButton()}
        

    Skill2.children[0].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S05-T2")

    Skill2.children[2].active=true
    Skill2.children[2].getComponent(gif).changeF(2,1)//体能
    Skill2.children[3].children[0].getComponent(cc.Label).string="1"
    Skill2.children[3].active=true
     
    
 
 //if (GeZiManager.PCP.getComponent(SXX).BL[4]==0) {
    //Skill2.active=false
 //}
    Skill3.active=false
    Skill4.active=false

    
    
    
    break;
   
    case "S09":
        if (GeZiManager.PCP.node.getComponent(S09).JX1.includes("S共舞")) {
            Skill3.active=false
        }  
        if (GeZiManager.PCP.node.getComponent(S09).JX1.includes("S光彩夺目")) {
          //  Skill2.active=false
        }    
    
    
    if (GeZiManager.PCP.TN<2||GeZiManager.PCP.t==0) {
        Skill1.parent.getComponent(CustomButton).disableButton()}
        

    Skill1.children[0].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S05-T2")

    Skill1.children[2].active=true
    Skill1.children[2].getComponent(gif).changeF(1,1)//体能
    Skill1.children[3].children[0].getComponent(cc.Label).string=""
    Skill1.children[3].active=false
    if (GeZiManager.PCP.TN<2||GeZiManager.PCP.t==0) {
        Skill4.parent.getComponent(CustomButton).disableButton()}
        

    Skill4.children[0].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S05-T2")

    Skill4.children[2].active=true
    Skill4.children[2].getComponent(gif).changeF(1,1)//体能
    Skill4.children[3].children[0].getComponent(cc.Label).string=""
    Skill4.children[3].active=false
     
    if (GeZiManager.PCP.TN<2||GeZiManager.PCP.qi<1) {
        Skill2.parent.getComponent(CustomButton).disableButton()}
        

    Skill2.children[0].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S05-T2")

    Skill2.children[2].active=true
    Skill2.children[2].getComponent(gif).changeF(1,1)//体能
    Skill2.children[3].children[0].getComponent(cc.Label).string="1"
    Skill2.children[3].active=true
 
 
    if (GeZiManager.PCP.TN<2||GeZiManager.PCP.qi<2) {
        Skill3.parent.getComponent(CustomButton).disableButton()}
        

    Skill3.children[0].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S05-T2")

    Skill3.children[2].active=true
    Skill3.children[2].getComponent(gif).changeF(1,1)//体能
    Skill3.children[3].children[0].getComponent(cc.Label).string="2"
    Skill3.children[3].active=true
 

    
    
    
    break;
    case "S07":
        //this.node.children[1].children[1].children[3].active=true
    
  
    if (GeZiManager.PCP.qi<1) {
        Skill2.parent.getComponent(CustomButton).disableButton() 
        Skill2.children[0].opacity=155
    }
    Skill1.children[0].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S08-T1")
    Skill2.children[0].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S08-T2")
    //this.node.children[1].children[1].children[1].active=true
    Skill1.children[3].active=false
    Skill2.children[3].active=true
    Skill2.children[3].children[0].getComponent(cc.Label).string="X"
   

    if (GeZiManager.PCP.getComponent(SXX).BL[0]==0) {
        Skill2.active=false
     }
   
     if (GeZiManager.PCP.getComponent(SXX).BL[1]==0) {
        Skill3.active=false
     }
    Skill1.children[2].getComponent(gif).changeF(2,1)
    Skill2.children[2].getComponent(gif).changeF(0,1)
 
    Skill4.active=false
    break; case "S10":
    //this.node.children[1].children[1].children[3].active=true

if (GeZiManager.PCP.TN<2||GeZiManager.PCP.qi<GeZiManager.PCP.node.getComponent(S10).qz) {
  Skill1.parent.getComponent(CustomButton).disableButton()
  Skill1.children[0].opacity=155
}
if (GeZiManager.PCP.TN<GeZiManager.PCP.node.getComponent(S10).SH) {
    Skill2.parent.getComponent(CustomButton).disableButton() 
    Skill2.children[0].opacity=155
}
Skill1.children[0].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S08-T1")
Skill2.children[0].getComponent(cc.Sprite).spriteFrame=this.Atlas.getSpriteFrame("S08-T2")
//this.node.children[1].children[1].children[1].active=true
Skill1.children[3].active=false
Skill2.children[3].active=true
Skill2.children[3].children[0].getComponent(cc.Label).string="X"




Skill1.children[2].getComponent(gif).changeF(2,1)
Skill2.children[2].getComponent(gif).changeF(0,1)
Skill3.active=false
Skill4.active=false
break;
   
    default:   
    Skill1.active=false
    Skill2.active=false
    Skill3.active=false
    Skill4.active=false
        break;
}
}
}

    qi(){
      


   console.log("nit")

     // if(MessageCenter.Text){  MessageCenter.MakeGMessage("AM",[GeZiManager.PCP.ZB],turn.day+GeZiManager.free,GeZiManager.PCP.Pturn,"Qi+");}
      
     MessageCenter.MakeGMessage("AM",[GeZiManager.PCP.ZB],1+GeZiManager.free,GeZiManager.PCP.Pturn,"qi");


}



attack(){

  


  if(GeZiManager.PCP.weapon.DT){if(this.PPC()){GeZiManager.PCP.weapon.attack()}}else{
    MessageCenter.MakeGMessage("AM",[GeZiManager.PCP.ZB],null,GeZiManager.PCP.Pturn,"attack");}
    this.DW=0
 
    

}
magic(){  
 
    MessageCenter.MakeMessage("UIManager","change",4);

for(let a of GeZiManager.PCP.magic1){a.Magic1()}


}




PASS(){
  
cc.find("Canvas/UIManager/BUIManager/BUI/BaseChoose/walk").getComponent(moveUI).bi()
    MessageCenter.MakeGMessage("GM",[0], turn.turn+1, turn.turn,"PASS"); 
}














//以下是商店部分



shopX(){
    MessageCenter.MakeMessage("AM",turn.turn,"getC")
    MessageCenter.MakeMessage("UIManager","change",1);

    for(let m of GeZiManager.PCP.shop3){m.Shop3();}
GeZiManager.PCP.ST();
}








getTeamZB(n:number,ZB:number){
    for(let a of this.AM.getComponent(AnimalManager).YuanGong){
    
        if(a.ZB==ZB){
        
    
        if(a.Pturn!=0&&(a.Pturn%2==n%2)){return true}else{return false}
}
    
    
   
    
    }
}















qic(qic:number){
  
    MessageCenter.MakeMessage("AM",turn.turn,"getQi")
    MessageCenter.MakeMessage("AM",turn.turn,"getZB")
if(GeZiManager.Qi>=qic){    MessageCenter.MakeSHMessage("AM",[GeZiManager.GeZi],qic,null,"Qi-");

GeZiManager.free=0;
return true}else{
    
   for(let ma of GeZiManager.label){
    ma.Fqic();
   }
    
    
    return false}


 } 




dA5(){

  
MessageCenter.MakeGMessage("SU",[],1,GeZiManager.PCP.Pturn,"buy")       

   
}


   





 


  /////////////////////


JX(){

    if(GeZiManager.PCP.getComponent(SXX).JX==true){}else{}

}



skill1(){

       GeZiManager.PCP.node.getComponent(SXX).skill1()
            
        
    }







skill2(){
GeZiManager.PCP.node.getComponent(SXX).skill2()}
skill3(){

    GeZiManager.PCP.node.getComponent(SXX).skill3()

}

skill4(){

    GeZiManager.PCP.node.getComponent(SXX).skill4()

}




}